﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebsiteDemo.Admin
{
    public partial class TrangChu1 : System.Web.UI.Page
    {
        DataBaseDataContext db = new DataBaseDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack){
                this.ListViewUser.DataSource = db.Users.ToList();
                this.ListViewUser.DataBind();
            }
        }
        protected void LinkButtonXoa_Click(object sender, EventArgs e){
            LinkButton lb = (LinkButton)sender;
            HiddenField hd = (HiddenField) lb.FindControl("HiddenFieldID");
            try {
                User us = db.Users.Single(u => u.Id.Equals(hd.Value));
                db.Users.DeleteOnSubmit(us);
                db.SubmitChanges();
                this.ListViewUser.DataSource = db.Users.ToList();
                this.ListViewUser.DataBind();
                this.LabelMessage.Text = "Xóa User thành công";
                
                
            }catch{
                this.LabelMessage.Text = "Xóa User không thành công";
            }
        }
    }
}